﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace Commander.Classes
{
    /// <summary>
    /// 
    /// </summary>
    class OpenPatch
    {
        //private string load = "Load.xml";
        private string _patchL;
        private string _patchR;

        public OpenPatch(string load)
        {
            if (File.Exists(load))
            {
                LoadPatch lp;
                StreamReader sr = new StreamReader(load);
                XmlSerializer dsr = new XmlSerializer(typeof(LoadPatch));
                lp = (LoadPatch)dsr.Deserialize(sr);
                sr.Close();
                if (Directory.Exists(lp.PatchL))
                {
                    _patchL = lp.PatchL;
                }
                else
                {
                    _patchL = GetPatch();
                }
                if (Directory.Exists(lp.PatchR))
                {
                    _patchR = lp.PatchR;
                }
                else
                {
                    _patchR = GetPatch();
                }
            }
            else
            {
                _patchL = _patchR = GetPatch();
            }
        }

        public string GetPatch()
        {
            DriveInfo[] allDrives = DriveInfo.GetDrives();
            foreach (var item in allDrives)
            {
                if (item.IsReady)
                {
                    return item.Name;
                }
            }
            return "";
        }

        public string PatchL
        {
            get
            {
                return _patchL;
            }
        }

        public string PatchR
        {
            get
            {
                return _patchR;
            }
        }
    }
}
